package com.mojo.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 * jdbc
 *
 * @author <a href="mailto:sjj@jianzhimao.com">mojo</a>
 * copyright (C), 2013-2021, 广州九尾信息科技有限公司
 * @date 2021/8/13 16:44
 */
public class JdbcDemo {
    public static final String URL = "jdbc:mysql://localhost:3306/jdbcdemo";
    public static final String USERNAME = "root";
    public static final String PASSWORD = "admin";

    public static void main(String[] args) throws Exception {
        //加载驱动
        Class.forName("com.mysql.cj.jdbc.Driver");
        //获取连接
        Connection connection = DriverManager.getConnection(URL, USERNAME, PASSWORD);
        //创建statement/preparedStatement对象
        PreparedStatement ps = connection.prepareStatement("SELECT * FROM `user` WHERE id=1");
        ResultSet rs = ps.executeQuery();
        while (rs.next()) {
            System.out.println(rs.getString("username"));
        }
        connection.close();

    }
}
